//
//  TJBaseTableViewController.m
//  TJSinaWeiBo_OC
//
//  Created by 唐后能 on 16/4/13.
//  Copyright © 2016年 itheima. All rights reserved.
//

#import "TJBaseTableViewController.h"
#import "TJVisitorView.h"
#import "TJHomeViewController.h"
#import "TJMessageViewController.h"
#import "TJDiscoverViewController.h"
#import "TJProfileViewController.h"
#import "TJOauthViewController.h"
#import "TJAccountViewModle.h"

@interface TJBaseTableViewController () <TJVisitorViewDelegate>

// 用户是否登录.
@property (nonatomic, assign) BOOL isUserLogin;

@end

@implementation TJBaseTableViewController

/**
 * 根据用户登录状态,自定义控制器的View.
 */
- (void)loadView {
    self.isUserLogin = [TJAccountViewModle shareAccountViewModle].isLogin;
    // 登录了显示自己的view,没登录显示自定义的访客视图view.
    self.isUserLogin ? [super loadView]: [self setupVisitorView];
}

// 创建访客视图.
- (void)setupVisitorView {

    // 1,创建访客视图.
    TJVisitorView *vistorView = [[TJVisitorView alloc] init];
    self.view = vistorView;
    // 设置访客视图的代理.
    vistorView.delegate = self;
    
    // 2,根据不同的子类,显示不同的bistorView.
    if ([self isKindOfClass:NSClassFromString(@"TJHomeViewController")]) {
        
        [vistorView wheelRotation];
    }else if ([self isKindOfClass:NSClassFromString(@"TJMessageViewController")]){
        
        [vistorView showOtherVistorViewWithCenterImgName:@"visitordiscover_image_message" messageText:@"登录后，别人评论你的微博，发给你的消息，都会在这里收到通知"];
    }else if ([self isKindOfClass:NSClassFromString(@"TJDiscoverViewController")]){
        
        [vistorView showOtherVistorViewWithCenterImgName:@"visitordiscover_image_message" messageText:@"登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过"];
    }else if ([self isKindOfClass:NSClassFromString(@"TJProfileViewController")]) {
        
        [vistorView showOtherVistorViewWithCenterImgName:@"visitordiscover_image_profile" messageText:@"登录后，你的微博、相册、个人资料会显示在这里，展示给别人"];
    }

    // 3,添加注册/登录按钮.
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"注册" style:UIBarButtonItemStylePlain target:self action:@selector(registClicked)];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(loginClicked)];
}


#pragma mark - 访客视图代理方法 & 导航栏按钮回调方法.
- (void)registClicked {

    NSLog(@"注册按钮被点击了");
}
- (void)loginClicked {
    
//    NSLog(@"登录按钮被点击了,跳转到授权页");
    TJOauthViewController *ouathVC = [[TJOauthViewController alloc] init];
    UINavigationController *navVC = [[UINavigationController alloc] initWithRootViewController:ouathVC];
    [self presentViewController:navVC animated:YES completion:nil];
}


@end
